﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label1.Text = "初始原文为";label2.Text = "加密密钥为";label3.Text = "加密后结果为";
            int lenght, lenght2, Tempascii, ascii, middle = 0, now = 0;
            string Plaintext, cipher, Ciphertext = "";
            Plaintext = this.textBox1.Text;
            cipher = this.textBox2.Text;
            lenght = Plaintext.Length;
            lenght2 = cipher.Length;
            char[] mychars = Plaintext.ToCharArray();
            char[] mychars2 = cipher.ToCharArray();
            for (int i = 0; i < lenght; i++)
            {
                Tempascii = ((int)mychars[i] - 97) + ((int)mychars2[now] - 97);
                now++;
                if (Tempascii > 25)
                {
                    middle = Tempascii % 26;
                    ascii = 97 + middle;
                }
                else
                {
                    ascii = 97 + Tempascii;
                }
                Ciphertext += (char)ascii;
                if (now >= lenght2)
                    now = 0;
            }
            this.textBox3.Text = Ciphertext;
            Console.WriteLine(this.textBox3.Text);
        }
    }
}
